<?php

/**
 * Description of BannerController
 * @author LinkTem  <LinkTem@126.com>
 * @date 2018-8-2
 */

namespace Cktadmin\Controller;

use Common\Controller\BasicAdmin;
use Common\Service\DataService;

class BannerController extends BasicAdmin {

    public $table = 'banner';

    public function index() {
        $this->title = '轮播图管理';
        $where = [];
        $get = I('get.');
        (isset($get['title']) && $get['title'] != '') && $where['title'] = ['LIKE', "%{$get['title']}%"];
        $db = M($this->table)->where($where)->order('sort asc,create_at desc');
        return parent::_list($db);
    }

    /**
     * 添加数据
     * @return type
     */
    public function add() {
        return parent::_form($this->table, 'form');
    }

    /**
     * 编辑数据
     * @return type
     */
    public function edit() {
        return parent::_form($this->table, 'form');
    }

    public function del() {
        if (DataService::update($this->table)) {
            $this->success('删除成功！');
        }
        $this->error('删除失败！');
    }

    /**
     * 禁用
     */
    public function forbid() {
        if (DataService::update($this->table)) {
            $this->success("禁用成功！", '');
        }
        $this->error("禁用失败，请稍候再试！");
    }

    /**
     * 启用
     */
    public function resume() {
        if (DataService::update($this->table)) {
            $this->success("启用成功！", '');
        }
        $this->error("启用失败，请稍候再试！");
    }

}
